package com.elinkway.infinitemovies.http.parser;

import com.elinkway.infinitemovies.bean.RelationAlbum;
import com.elinkway.infinitemovies.bean.RelationList;

import org.json.JSONArray;
import org.json.JSONObject;

public class RelationListParser extends LVideoMobileParser<RelationList> {

	@Override
	public RelationList parse(JSONObject data) throws Exception {
		JSONArray array = data.getJSONArray("items");
		if (array == null) {
			return null;
		}
		String bucket =data.optString("bucket");
		String reid =data.optString("reid");
		RelationList ret = new RelationList();
		for (int i = 0 ; i< array.length(); i++){
			JSONObject obj = array.getJSONObject(i);
			RelationAlbum album = new RelationAlbum();
			album.setReid(reid);
			album.setBucket(bucket);
			album.setNowEpisode(obj.getString("now_episode"));
			album.setTitle(obj.getString("title"));
			album.setArea(obj.getString("area"));
			album.setCategoryName(obj.getString("category_name"));
			album.setScore(obj.getString("score"));
			album.setVt(obj.getString("vt"));
			album.setYear(obj.getString("year"));
			album.setAid(obj.getString("aid"));
			album.setPic(obj.getString("pic"));
			album.setEpisodes(obj.getString("episodes"));
			album.setSubCategory(obj.getString("sub_category"));
			album.setIsEnd(obj.getString("is_end"));
			ret.add(album);
		}
		return ret;
	}

}
